//function that will disable the ability to select text when it's actually a link (like the navigation divs).    
$.fn.extend({ 
                disableSelection: function() { 
                    this.each(function() { 
                        if (typeof this.onselectstart != 'undefined') {
                            this.onselectstart = function() { return false; };
                        } else if (typeof this.style.MozUserSelect != 'undefined') {
                            this.style.MozUserSelect = 'none';
                        } else {
                            this.onmousedown = function() { return false; };
                        }
                    }); 
                } 
            });

//Function that will position all the activities and display them if in the right week.
function positionAllActivities(i) {
	    	var elems = document.getElementsByTagName("div");
	        var divCollection = $.makeArray(elems);
	        var currentWeek = parseInt($("#theScheduledWeek").text().substr(5,2));
			
	        $.each(divCollection, function(key, val){
	        	if(val.getAttribute("class") == "activityDiv") {
	        	val.style.display = "none";
	        	}
	        });
	        $.each(divCollection, function (key, val) {
	            if(val.getAttribute("class") == "activityDiv") {
	            	
	                var text = val.innerHTML;
	                var indexHaak = text.indexOf("}");
	                var indexExcl = text.indexOf("!");
	                var indexQues = text.indexOf("?");
	                var indexBall = text.indexOf("&");
	                var indexStar = text.indexOf("*");

	       if(i==1 && text.indexOf("}")==-1 && text.indexOf("&")==-1){
	    	   		var week = text.substr(indexStar+6,3);
	                if(week.indexOf("*")!=-1)
	                	{
	                	week.replace("*","");
	                	
	                	}
	                week = parseInt(week);
	                if(week==currentWeek)
	                	{
	                	val.style.display = "inline";
	                	}
	       		}
	       
	       else{         
               		var week		= parseInt(text.substr(indexStar+1));
      		
	                if(week==currentWeek){
	                if(indexBall!=0){												//check if no exceptional case
	                var actName		= text.substr(0,indexBall);
	                var actDescr	= text.substr(indexBall+9,indexHaak-indexBall-9);
	                var marginLeft 	= text.substr(indexHaak+1,indexExcl-indexHaak-1);
	                var marginTop 	= text.substr(indexExcl+1,indexQues-indexExcl-1);
	                var height 		= text.substr(indexQues+1,indexStar-indexQues-1);
	                var heightInt 	= parseInt(height.substr(0,height.length-2));
	                }
	                else{															//exceptional case, do nothing
	                }
	                if(heightInt>45){												//if there is enough room, show description
	                val.innerHTML=''+actName+'<br/>'+actDescr+'<br/><p id="hiddenWeek">*Week: '+week+'</p>';
	                }
	                else{															//otherwise just show the name
	                val.innerHTML=''+actName+'<br/><p id="hiddenWeek">*Week: '+week+'*</p>';
	                }
	                																//position and show the activity
	                val.style.height = height;
	                val.style.marginLeft = marginLeft;
	                val.style.marginTop = marginTop;
	                val.style.display = "inline";
	                
	                }//close if loop that checks if activity is in current week
	            } 
	            }
	        });
		}

function deleteNote(idnumber){
	var data = { id: idnumber+""}
	$.ajax({
		  type: 'POST',
		  url: "/noteservlet",
		  data: data,
		  success: deleteNoteSuccess(data)
		});
}

function deleteNoteSuccess(data){
	window.location.reload();
}

$(document).ready(function(){
	$(".contentDiv").hide();
	$("#contentDivHome").show();
	$("#navHome").disableSelection();
	$("#navGoogle").disableSelection();
	$("#navSchedule").disableSelection();
	$("#vorigeWeek").disableSelection();
	$("#volgendeWeek").disableSelection();
		
	function getStyle(el, styleProp) {
		var x = document.getElementById(el);
		if (x.currentStyle)
			var y = x.currentStyle[styleProp];
		else if (window.getComputedStyle)
			var y = document.defaultView.getComputedStyle(x, null)
					.getPropertyValue(styleProp);
		return y;
	}
	var bodyWidth = parseFloat($("body").css("width"));
	var middleSectionWidth = parseFloat($("#middleSection").css("width"));
	$("#middleSection").css("margin-left", ((bodyWidth-middleSectionWidth)/2)+ "px");
	var middleSectionMargin = ((bodyWidth-middleSectionWidth)/2);
	var usernamePadding = parseFloat($("#usernameTopDiv").css(
			"paddingLeft"));
	var usernameWidth = parseFloat($("#usernameTopDiv").css("width"));
	var navBarMargin = middleSectionMargin - usernamePadding
			- usernameWidth;
	$("#navigationBar").css("margin-left", navBarMargin + "px");

	//Adjust on window resize
    var prevWidth = $(document).width();
	$(window).resize(function(e) {
	    var currentWidth = $(document).width();
		if((parseFloat($("#middleSection").css("margin-left"))<230) && (prevWidth>=currentWidth)){
		}
		else if(currentWidth>1490){
			calculateMarginsOnResize();
		}
	    prevWidth = currentWidth;
	});
	
	$('.navigation-div').mouseover(function(){
			$(this).css("color","white");
			$(this).css('cursor','pointer');
	});
	
	$('.navigation-div').mouseout(function(){
			$(this).css("color","#BBBBBB");
	});
	
/*NAVHOME SCRIPTS*/
	$('#navHome').click(function(){
		$(".contentDiv").hide();
		$("#contentDivHome").show();
	});
/*NAVRSA SCRIPTS*/
	$('#navRSA').click(function(){
		rsaClicked();
	});
/*NAVSCHEDULE SCRIPTS*/
	$('#navSchedule').click(function(){
		window.location="schedule.jsp"
//		$(".contentDiv").hide();
//		$("#contentDivSchedule").show();
//	    positionAllActivities(0);
	});
/*NAVRECIPE CLICK*/
	$('#navRecipe').click(function(){
		window.location="recipes.jsp"
	});

	$('.activityDiv').mouseover(function(){
		$(this).css("background-color","#707AFA");
	});
	$('.activityDiv').mouseout(function(){
		$(this).css("background-color","#FFFF99");
	});
	
	//Enkel cijfers toegelaten als duur.
    $("#lengte").keypress(function(event) {
        // Allow only backspace and delete
        if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 37) {
            // let it happen, don't do anything
        }
        else {
            // Ensure that it is a number and stop the keypress
            if (event.keyCode < 48 || event.keyCode > 57) {
                event.preventDefault(); 
            }   
        }
    });   
    
    //Extra check dat enkel cijfers zijn ingevuld als duur (bijvoorbeeld door copy paste toch letters ingevuld)
    $("#activityForm").submit(function(){
    	
        var inputVal = $('#lengte').val();
        var characterReg = /^[0-9]/;
        if (!characterReg.test(inputVal)) {
            alert('You entered an invalid duration');
            return false;
        }
        else
        { 
        	$("#activityForm").submit();
        }
     });
	//User selecteert een tijdstip//
	$(".scheduleTime").click(function(e){
		e.preventDefault();
		//Set the selected week
		var strweek = $("#theScheduledWeek").text();
		var week = strweek.substr(5,2);
		$("#week").text("Week: "+week);
		$("[name=week]").val(parseInt(week));
		
		//Set the selected date
		var td = e.target || e.srcElement
		var collumn = td.cellIndex;
		var date = "null";
		if(collumn==1){ date = $("#mondayDate").text(); }
		if(collumn==2){ date = $("#tuesdayDate").text(); }
		if(collumn==3){ date = $("#wednesdayDate").text(); }
		if(collumn==4){ date = $("#thursdayDate").text(); }
		if(collumn==5){ date = $("#fridayDate").text(); }
		$("#date").text("Date: "+date);
		$("[name=date]").val(date);
	});
	
	$("#scheduleTable tbody tr").click(function(){
	
		var row = this.rowIndex;
		var time = "null";
		if(row==1){time = "7:00";}
		if(row==2){time = "7:30";}
		if(row==3){time = "8:00";}
		if(row==4){time = "8:30";}
		if(row==5){time = "9:00";}
		if(row==6){time = "9:30";}
		if(row==7){time = "10:00";}
		if(row==8){time = "10:30";}
		if(row==9){time = "11:00";}
		if(row==10){time = "11:30";}
		if(row==11){time = "12:00";}
		if(row==12){time = "12:30";}
		if(row==13){time = "13:00";}
		if(row==14){time = "13:30";}
		if(row==15){time = "14:00";}
		if(row==16){time = "14:30";}
		if(row==17){time = "15:00";}
		if(row==18){time = "15:30";}
		if(row==19){time = "16:00";}
		if(row==20){time = "16:30";}
		if(row==21){time = "17:00";}
		if(row==22){time = "17:30";}
		if(row==23){time = "18:00";}
		if(row==24){time = "18:30";}
		if(row==25){time = "19:00";}
		if(row==26){time = "19:30";}
		if(row==27){time = "20:00";}
		$("#start").text("Start: "+time);
		$("[name=start]").val(time);
		
	});
	
	$('td').hover(function(){

	    $(this).css('background-color','#E4E4E4');
	    $('td:first', $(this).parents('tr')).css({'background-color':'#CFD2FF','color':'#000000'});
	},
	function(){

	    $(this).css('background-color','transparent');
	    $('td:first', $(this).parents('tr')).css({'background-color':'transparent','color':'#002436'});
	    $('td:first', $(this).parents('tr')).css('border-top', 'none');
	    $('td:first', $(this).parents('tr')).css('border-bottom', 'none');
	    $('td:first', $(this).parents('tr')).css('border-left', '1px solid black');
	    $('td:first', $(this).parents('tr')).css('border-right', '1px solid black');
	});
	
	//User hovert over "vorige" of "volgende" om de week te veranderen.
	$('#vorigeWeek').hover(function(){
	$("#vorigeWeek").css('cursor','pointer');
	});
	
	$('#volgendeWeek').hover(function(){
	$("#volgendeWeek").css('cursor','pointer');
	});
	
	//User verandert de week//
	$("#volgendeWeek").click(function(event){
		event.preventDefault();
		//Pas de week aan//
		var str = $("#theScheduledWeek").text();
		console.log(str);
		var oudeweek = parseInt(str.substr(5,2));
		console.log(oudeweek);
		if(oudeweek == 52){}
		else{
		var nieuweweek = oudeweek + 1;
		$("#theScheduledWeek").text("Week "+nieuweweek);
		//Pas de data van de week aan//
		var mondayDate = $("#mondayDate").text();
		var tuesdayDate = $("#tuesdayDate").text();
		var wednesdayDate = $("#wednesdayDate").text();
		var thursdayDate = $("#thursdayDate").text();
		var fridayDate = $("#fridayDate").text();
		
		var mondayDayOld = mondayDate.substr(0,2);
		var mondayMonthOld = mondayDate.substr(3,2);
		var mondayYearOld = mondayDate.substr(6,4);
		
		var tuesdayDayOld = tuesdayDate.substr(0,2);
		var tuesdayMonthOld = tuesdayDate.substr(3,2);
		var tuesdayYearOld = tuesdayDate.substr(6,4);
		
		var wednesdayDayOld = wednesdayDate.substr(0,2);
		var wednesdayMonthOld = wednesdayDate.substr(3,2);
		var wednesdayYearOld = wednesdayDate.substr(6,4);
		
		var thursdayDayOld = thursdayDate.substr(0,2);
		var thursdayMonthOld = thursdayDate.substr(3,2);
		var thursdayYearOld = thursdayDate.substr(6,4);
		
		var fridayDayOld = fridayDate.substr(0,2);
		var fridayMonthOld = fridayDate.substr(3,2);
		var fridayYearOld = fridayDate.substr(6,4);
/*INITIALISATION OF VARIABLES*/	
		var mondayDayNew = 1;
		var tuesdayDayNew = 1;
		var wednesdayDayNew = 1;
		var thursdayDayNew = 1;
		var fridayDayNew = 1;
		var mondayMonthNew = 1;
		var tuesdayMonthNew = 1;
		var wednesdayMonthNew = 1;
		var thursdayMonthNew = 1;
		var fridayMonthNew = 1;
		var mondayYearNew = mondayYearOld;
		var tuesdayYearNew = tuesdayYearOld;
		var wednesdayYearNew = wednesdayYearOld;
		var thursdayYearNew = thursdayYearOld;
		var fridayYearNew = fridayYearOld;
/*ADD 1 TO THE DAY OF MONDAY*/		
		/*IMPORTANT REMARK: THE METHOD PARSEINT(X) PARSES STRINGS TO INTEGERS USING THE OCTADECIMAL BASE, BECAUSE FOR EXAMPLE: 08 AND 09 DO NOT EXIST IN OCTADECIMAL FORM, IT RETURNS 0 FOR THESE INSTEAD OF THE EXPECTED 8 AND 9!, USE PARSEINT(X,10) TO SPECIFY BASE 10 USAGE */
		if(mondayDayOld>0 & mondayDayOld<32)
			{
			if(mondayMonthOld==01 | mondayMonthOld==03 | mondayMonthOld==05 | mondayMonthOld==07 | mondayMonthOld==08 | mondayMonthOld==10 | mondayMonthOld==12) //31 day month
				{
				if(mondayDayOld==31)
					{
					mondayDayNew = 07;
					mondayMonthNew = parseInt(mondayMonthOld,10)+1;
					if(mondayMonthNew==13)
						{
						mondayMonthNew=1;
						mondayYearNew= parseInt(mondayYearOld,10)+1;
						}
					}
				if(mondayDayOld==30)
				{
				mondayDayNew = 06;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				if(mondayMonthNew==13)
					{
					mondayMonthNew=1;
					mondayYearNew= parseInt(mondayYearOld,10)+1;
					}
				}
				if(mondayDayOld==29)
				{
				mondayDayNew = 05;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				if(mondayMonthNew==13)
					{
					mondayMonthNew=1;
					mondayYearNew= parseInt(mondayYearOld,10)+1;
					}
				}
				if(mondayDayOld==28)
				{
				mondayDayNew = 04;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				if(mondayMonthNew==13)
					{
					mondayMonthNew=1;
					mondayYearNew= parseInt(mondayYearOld,10)+1;
					}
				}
				if(mondayDayOld==27)
				{
				mondayDayNew = 03;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				if(mondayMonthNew==13)
					{
					mondayMonthNew=1;
					mondayYearNew= parseInt(mondayYearOld,10)+1;
					}
				}
				if(mondayDayOld==26)
				{
				mondayDayNew = 02;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				if(mondayMonthNew==13)
					{
					mondayMonthNew=1;
					mondayYearNew= parseInt(mondayYearOld,10)+1;
					}
				}
				if(mondayDayOld==25)
				{
				mondayDayNew = 01;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				if(mondayMonthNew==13)
					{
					mondayMonthNew=1;
					mondayYearNew= parseInt(mondayYearOld,10)+1;
					}
				}
				if(mondayDayOld!=25 & mondayDayOld!=26 & mondayDayOld!=27 & mondayDayOld!=28 & mondayDayOld!=29 & mondayDayOld!=30 & mondayDayOld!=31)
					{
					mondayDayNew = parseInt(mondayDayOld,10) +7;
					mondayMonthNew = mondayMonthOld;
					mondayYearNew = mondayYearOld;
					}
				}
			if(mondayMonthOld==04 | mondayMonthOld==06 | mondayMonthOld==09 | mondayMonthOld==11 )//30 day month
				{
				if(mondayDayOld==30)
				{
				mondayDayNew = 07;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				}
				if(mondayDayOld==29)
				{
				mondayDayNew = 06;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				}
				if(mondayDayOld==28)
				{
				mondayDayNew = 05;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				}
				if(mondayDayOld==27)
				{
				mondayDayNew = 04;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				}
				if(mondayDayOld==26)
				{
				mondayDayNew = 03;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				}
				if(mondayDayOld==25)
				{
				mondayDayNew = 02;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				}
				if(mondayDayOld==24)
				{
				mondayDayNew = 01;
				mondayMonthNew = parseInt(mondayMonthOld,10)+1;
				}
				if(mondayDayOld!=24 & mondayDayOld!=25 & mondayDayOld!=26 & mondayDayOld!=27 & mondayDayOld!=28 & mondayDayOld!=29 & mondayDayOld!=30)
					{
					mondayDayNew = parseInt(mondayDayOld,10) +7;
					mondayMonthNew = mondayMonthOld;
					mondayYearNew = mondayYearOld;
					}
				}
			if(mondayMonthOld==02)
				{
				if(mondayYearOld==2012 | mondayYearOld==2016 | mondayYearOld==2020 | mondayYearOld==2024 | mondayYearOld==2028 | mondayYearOld==2032)
					{
					if(mondayDayOld==29)
					{
					mondayDayNew = 07;
					mondayMonthNew = parseInt(mondayMonthOld,10)+1;
					}
					if(mondayDayOld==28)
					{
					mondayDayNew = 06;
					mondayMonthNew = parseInt(mondayMonthOld,10)+1;
					}
					if(mondayDayOld==27)
					{
					mondayDayNew = 05;
					mondayMonthNew = parseInt(mondayMonthOld,10)+1;
					}
					if(mondayDayOld==26)
					{
					mondayDayNew = 04;
					mondayMonthNew = parseInt(mondayMonthOld,10)+1;
					}
					if(mondayDayOld==25)
					{
					mondayDayNew = 03;
					mondayMonthNew = parseInt(mondayMonthOld,10)+1;
					}
					if(mondayDayOld==24)
					{
					mondayDayNew = 02;
					mondayMonthNew = parseInt(mondayMonthOld,10)+1;
					}
					if(mondayDayOld==23)
					{
					mondayDayNew = 01;
					mondayMonthNew = parseInt(mondayMonthOld,10)+1;
					}
					if( mondayDayOld!=23 & mondayDayOld!=24 & mondayDayOld!=25 & mondayDayOld!=26 & mondayDayOld!=27 & mondayDayOld!=28 & mondayDayOld!=29)
						{
						mondayDayNew = parseInt(mondayDayOld,10) +7;
						mondayMonthNew = mondayMonthOld;
						mondayYearNew = mondayYearOld;
						}
					}
				if(mondayYearOld!=2012 & mondayYearOld!=2016 & mondayYearOld!=2020 & mondayYearOld!=2024 & mondayYearOld!=2028 & mondayYearOld!=2032)
					{
					if(mondayDayOld==28)
						{
						mondayDayNew = 07;
						mondayMonthNew = parseInt(mondayMonthOld,10)+1;
						}
					if(mondayDayOld==27)
						{
						mondayDayNew = 06;
						mondayMonthNew = parseInt(mondayMonthOld,10)+1;
						}
					if(mondayDayOld==26)
						{
						mondayDayNew = 05;
						mondayMonthNew = parseInt(mondayMonthOld,10)+1;
						}
					if(mondayDayOld==25)
						{
						mondayDayNew = 04;
						mondayMonthNew = parseInt(mondayMonthOld,10)+1;
						}
					if(mondayDayOld==24)
						{
						mondayDayNew = 03;
						mondayMonthNew = parseInt(mondayMonthOld,10)+1;
						}
					if(mondayDayOld==23)
						{
						mondayDayNew = 02;
						mondayMonthNew = parseInt(mondayMonthOld,10)+1;
						}
					if(mondayDayOld==22)
						{
						mondayDayNew = 01;
						mondayMonthNew = parseInt(mondayMonthOld,10)+1;
						}
					if(mondayDayOld!=22 & mondayDayOld!=23 & mondayDayOld!=24 & mondayDayOld!=25 & mondayDayOld!=26 & mondayDayOld!=27 & mondayDayOld!=28 )
						{
						mondayDayNew = parseInt(mondayDayOld,10) +7;
						mondayMonthNew = mondayMonthOld;
						mondayYearNew = mondayYearOld;
						}
					}
				}
			}
/*ADD 1 TO THE DAY OF TUESDAY*/	
		if(tuesdayDayOld>0 & tuesdayDayOld<32)
		{
		if(tuesdayMonthOld==01 | tuesdayMonthOld==03 | tuesdayMonthOld==05 | tuesdayMonthOld==07 | tuesdayMonthOld==08 | tuesdayMonthOld==10 | tuesdayMonthOld==12) //31 day month
			{
			if(tuesdayDayOld==31)
				{
				tuesdayDayNew = 07;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				if(tuesdayMonthNew==13)
					{
					tuesdayMonthNew=1;
					tuesdayYearNew= parseInt(tuesdayYearOld,10)+1;
					}
				}
			if(tuesdayDayOld==30)
			{
			tuesdayDayNew = 06;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
			if(tuesdayMonthNew==13)
				{
				tuesdayMonthNew=1;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)+1;
				}
			}
			if(tuesdayDayOld==29)
			{
			tuesdayDayNew = 05;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
			if(tuesdayMonthNew==13)
				{
				tuesdayMonthNew=1;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)+1;
				}
			}
			if(tuesdayDayOld==28)
			{
			tuesdayDayNew = 04;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
			if(tuesdayMonthNew==13)
				{
				tuesdayMonthNew=1;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)+1;
				}
			}
			if(tuesdayDayOld==27)
			{
			tuesdayDayNew = 03;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
			if(tuesdayMonthNew==13)
				{
				tuesdayMonthNew=1;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)+1;
				}
			}
			if(tuesdayDayOld==26)
			{
			tuesdayDayNew = 02;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
			if(tuesdayMonthNew==13)
				{
				tuesdayMonthNew=1;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)+1;
				}
			}
			if(tuesdayDayOld==25)
			{
			tuesdayDayNew = 01;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
			if(tuesdayMonthNew==13)
				{
				tuesdayMonthNew=1;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)+1;
				}
			}
			if(tuesdayDayOld!=25 & tuesdayDayOld!=26 & tuesdayDayOld!=27 & tuesdayDayOld!=28 & tuesdayDayOld!=29 & tuesdayDayOld!=30 & tuesdayDayOld!=31)
				{
				tuesdayDayNew = parseInt(tuesdayDayOld,10) +7; 
				tuesdayMonthNew = tuesdayMonthOld;
				tuesdayYearNew = tuesdayYearOld;
				}
			}
		if(tuesdayMonthOld==04 | tuesdayMonthOld==06 | tuesdayMonthOld==09 | tuesdayMonthOld==11 )//30 day month
			{
		if(tuesdayDayOld==30)
		{
		tuesdayDayNew = 07;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
		}
		if(tuesdayDayOld==29)
		{
		tuesdayDayNew = 06;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
		}
		if(tuesdayDayOld==28)
		{
		tuesdayDayNew = 05;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
		}
		if(tuesdayDayOld==27)
		{
		tuesdayDayNew = 04;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
		}
		if(tuesdayDayOld==26)
		{
		tuesdayDayNew = 03;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
		}
		if(tuesdayDayOld==25)
		{
		tuesdayDayNew = 02;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
		}
		if(tuesdayDayOld==24)
		{
		tuesdayDayNew = 01;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
		}
		if(tuesdayDayOld!=24 & tuesdayDayOld!=25 & tuesdayDayOld!=26 & tuesdayDayOld!=27 & tuesdayDayOld!=28 & tuesdayDayOld!=29 & tuesdayDayOld!=30)
				{
				tuesdayDayNew = parseInt(tuesdayDayOld,10) +7;
				tuesdayMonthNew = tuesdayMonthOld;
				tuesdayYearNew = tuesdayYearOld;
				}
			}
		if(tuesdayMonthOld==02)
			{
			if(tuesdayYearOld==2012 | tuesdayYearOld==2016 | tuesdayYearOld==2020 | tuesdayYearOld==2024 | tuesdayYearOld==2028 | tuesdayYearOld==2032)
				{
				if(tuesdayDayOld==29)
				{
				tuesdayDayNew = 07;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==28)
				{
				tuesdayDayNew = 06;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==27)
				{
				tuesdayDayNew = 05;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==26)
				{
				tuesdayDayNew = 04;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==25)
				{
				tuesdayDayNew = 03;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==24)
				{
				tuesdayDayNew = 02;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==23)
				{
				tuesdayDayNew = 01;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld!=23 & tuesdayDayOld!=24 & tuesdayDayOld!=25 & tuesdayDayOld!=26 & tuesdayDayOld!=27 & tuesdayDayOld!=28 & tuesdayDayOld!=29)
					{
					tuesdayDayNew = parseInt(tuesdayDayOld,10) +7;
					tuesdayMonthNew = tuesdayMonthOld;
					tuesdayYearNew = tuesdayYearOld;
					}
				}
			if(tuesdayYearOld!=2012 & tuesdayYearOld!=2016 & tuesdayYearOld!=2020 & tuesdayYearOld!=2024 & tuesdayYearOld!=2028 & tuesdayYearOld!=2032)
				{
				if(tuesdayDayOld==28)
				{
				tuesdayDayNew = 07;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==27)
				{
				tuesdayDayNew = 06;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==26)
				{
				tuesdayDayNew = 05;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==25)
				{
				tuesdayDayNew = 04;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==24)
				{
				tuesdayDayNew = 03;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==23)
				{
				tuesdayDayNew = 02;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld==22)
				{
				tuesdayDayNew = 01;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)+1;
				}
				if(tuesdayDayOld!=22 & tuesdayDayOld!=23 & tuesdayDayOld!=24 & tuesdayDayOld!=25 & tuesdayDayOld!=26 & tuesdayDayOld!=27 & tuesdayDayOld!=28)
					{
					tuesdayDayNew = parseInt(tuesdayDayOld,10) +7;
					tuesdayMonthNew = tuesdayMonthOld;
					tuesdayYearNew = tuesdayYearOld;
					}
				}
			}
		}
/*ADD 1 TO THE DAY OF WEDNESDAY*/	
		if(wednesdayDayOld>0 & wednesdayDayOld<32)
		{
		if(wednesdayMonthOld==01 | wednesdayMonthOld==03 | wednesdayMonthOld==05 | wednesdayMonthOld==07 | wednesdayMonthOld==08 | wednesdayMonthOld==10 | wednesdayMonthOld==12) //31 day month
			{
			if(wednesdayDayOld==31)
				{
				wednesdayDayNew = 07;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				if(wednesdayMonthNew==13)
					{
					wednesdayMonthNew=1;
					wednesdayYearNew= parseInt(wednesdayYearOld,10)+1;
					}
				}
			if(wednesdayDayOld==30)
			{
			wednesdayDayNew = 06;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			if(wednesdayMonthNew==13)
				{
				wednesdayMonthNew=1;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)+1;
				}
			}
			if(wednesdayDayOld==29)
			{
			wednesdayDayNew = 05;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			if(wednesdayMonthNew==13)
				{
				wednesdayMonthNew=1;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)+1;
				}
			}
			if(wednesdayDayOld==28)
			{
			wednesdayDayNew = 04;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			if(wednesdayMonthNew==13)
				{
				wednesdayMonthNew=1;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)+1;
				}
			}
			if(wednesdayDayOld==27)
			{
			wednesdayDayNew = 03;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			if(wednesdayMonthNew==13)
				{
				wednesdayMonthNew=1;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)+1;
				}
			}
			if(wednesdayDayOld==26)
			{
			wednesdayDayNew = 02;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			if(wednesdayMonthNew==13)
				{
				wednesdayMonthNew=1;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)+1;
				}
			}
			if(wednesdayDayOld==25)
			{
			wednesdayDayNew = 01;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			if(wednesdayMonthNew==13)
				{
				wednesdayMonthNew=1;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)+1;
				}
			}
			if(wednesdayDayOld!=25 & wednesdayDayOld!=26 & wednesdayDayOld!=27 & wednesdayDayOld!=28 & wednesdayDayOld!=29 & wednesdayDayOld!=30 & wednesdayDayOld!=31)
				{
				wednesdayDayNew = parseInt(wednesdayDayOld,10) +7; 
				wednesdayMonthNew = wednesdayMonthOld;
				wednesdayYearNew = wednesdayYearOld;
				}
			}
		if(wednesdayMonthOld==04 | wednesdayMonthOld==06 | wednesdayMonthOld==09 | wednesdayMonthOld==11 )//30 day month
			{
			if(wednesdayDayOld==30)
			{
			wednesdayDayNew = 07;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			}
			if(wednesdayDayOld==29)
			{
			wednesdayDayNew = 06;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			}
			if(wednesdayDayOld==28)
			{
			wednesdayDayNew = 05;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			}
			if(wednesdayDayOld==27)
			{
			wednesdayDayNew = 04;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			}
			if(wednesdayDayOld==26)
			{
			wednesdayDayNew = 03;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			}
			if(wednesdayDayOld==25)
			{
			wednesdayDayNew = 02;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			}
			if(wednesdayDayOld==24)
			{
			wednesdayDayNew = 01;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
			}
			if(wednesdayDayOld!=24 & wednesdayDayOld!=25 & wednesdayDayOld!=26 & wednesdayDayOld!=27 & wednesdayDayOld!=28 & wednesdayDayOld!=29 & wednesdayDayOld!=30)
				{
				wednesdayDayNew = parseInt(wednesdayDayOld,10) +7;
				wednesdayMonthNew = wednesdayMonthOld;
				wednesdayYearNew = wednesdayYearOld;
				}
			}
		if(wednesdayMonthOld==02)
			{
			if(wednesdayYearOld==2012 | wednesdayYearOld==2016 | wednesdayYearOld==2020 | wednesdayYearOld==2024 | wednesdayYearOld==2028 | wednesdayYearOld==2032)
				{
				if(wednesdayDayOld==29)
				{
				wednesdayDayNew = 07;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==28)
				{
				wednesdayDayNew = 06;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==27)
				{
				wednesdayDayNew = 05;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==26)
				{
				wednesdayDayNew = 04;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==25)
				{
				wednesdayDayNew = 03;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==24)
				{
				wednesdayDayNew = 02;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==23)
				{
				wednesdayDayNew = 01;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld!=23 & wednesdayDayOld!=24 & wednesdayDayOld!=25 & wednesdayDayOld!=26 & wednesdayDayOld!=27 & wednesdayDayOld!=28 & wednesdayDayOld!=29)
					{
					wednesdayDayNew = parseInt(wednesdayDayOld,10) +7;
					wednesdayMonthNew = wednesdayMonthOld;
					wednesdayYearNew = wednesdayYearOld;
					}
				}
			if(wednesdayYearOld!=2012 & wednesdayYearOld!=2016 & wednesdayYearOld!=2020 & wednesdayYearOld!=2024 & wednesdayYearOld!=2028 & wednesdayYearOld!=2032)
				{
				if(wednesdayDayOld==28)
				{
				wednesdayDayNew = 07;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==27)
				{
				wednesdayDayNew = 06;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==26)
				{
				wednesdayDayNew = 05;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==25)
				{
				wednesdayDayNew = 04;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==24)
				{
				wednesdayDayNew = 03;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==23)
				{
				wednesdayDayNew = 02;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld==22)
				{
				wednesdayDayNew = 01;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)+1;
				}
				if(wednesdayDayOld!=22 & wednesdayDayOld!=23 & wednesdayDayOld!=24 & wednesdayDayOld!=25 & wednesdayDayOld!=26 & wednesdayDayOld!=27 & wednesdayDayOld!=28)
					{
					wednesdayDayNew = parseInt(wednesdayDayOld,10) +7;
					wednesdayMonthNew = wednesdayMonthOld;
					wednesdayYearNew = wednesdayYearOld;
					}
				}
			}
		}
/*ADD 1 TO THE DAY OF THURSDAY*/	
		if(thursdayDayOld>0 & thursdayDayOld<32)
		{
		if(thursdayMonthOld==01 | thursdayMonthOld==03 | thursdayMonthOld==05 | thursdayMonthOld==07 | thursdayMonthOld==08 | thursdayMonthOld==10 | thursdayMonthOld==12) //31 day month
			{
			if(thursdayDayOld==31)
				{
				thursdayDayNew = 07;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				if(thursdayMonthNew==13)
					{
					thursdayMonthNew=1;
					thursdayYearNew= parseInt(thursdayYearOld,10)+1;
					}
				}
			if(thursdayDayOld==30)
			{
			thursdayDayNew = 06;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			if(thursdayMonthNew==13)
				{
				thursdayMonthNew=1;
				thursdayYearNew= parseInt(thursdayYearOld,10)+1;
				}
			}
			if(thursdayDayOld==29)
			{
			thursdayDayNew = 05;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			if(thursdayMonthNew==13)
				{
				thursdayMonthNew=1;
				thursdayYearNew= parseInt(thursdayYearOld,10)+1;
				}
			}
			if(thursdayDayOld==28)
			{
			thursdayDayNew = 04;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			if(thursdayMonthNew==13)
				{
				thursdayMonthNew=1;
				thursdayYearNew= parseInt(thursdayYearOld,10)+1;
				}
			}
			if(thursdayDayOld==27)
			{
			thursdayDayNew = 03;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			if(thursdayMonthNew==13)
				{
				thursdayMonthNew=1;
				thursdayYearNew= parseInt(thursdayYearOld,10)+1;
				}
			}
			if(thursdayDayOld==26)
			{
			thursdayDayNew = 02;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			if(thursdayMonthNew==13)
				{
				thursdayMonthNew=1;
				thursdayYearNew= parseInt(thursdayYearOld,10)+1;
				}
			}
			if(thursdayDayOld==25)
			{
			thursdayDayNew = 01;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			if(thursdayMonthNew==13)
				{
				thursdayMonthNew=1;
				thursdayYearNew= parseInt(thursdayYearOld,10)+1;
				}
			}
			if(thursdayDayOld!=25 & thursdayDayOld!=26 & thursdayDayOld!=27 & thursdayDayOld!=28 & thursdayDayOld!=29 & thursdayDayOld!=30 & thursdayDayOld!=31)
				{
				thursdayDayNew = parseInt(thursdayDayOld,10) +7; 
				thursdayMonthNew = thursdayMonthOld;
				thursdayYearNew = thursdayYearOld;
				}
			}
		if(thursdayMonthOld==04 | thursdayMonthOld==06 | thursdayMonthOld==09 | thursdayMonthOld==11 )//30 day month
			{
			if(thursdayDayOld==30)
			{
			thursdayDayNew = 07;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			}
			if(thursdayDayOld==29)
			{
			thursdayDayNew = 06;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			}
			if(thursdayDayOld==28)
			{
			thursdayDayNew = 05;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			}
			if(thursdayDayOld==27)
			{
			thursdayDayNew = 04;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			}
			if(thursdayDayOld==26)
			{
			thursdayDayNew = 03;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			}
			if(thursdayDayOld==25)
			{
			thursdayDayNew = 02;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			}
			if(thursdayDayOld==24)
			{
			thursdayDayNew = 01;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
			}
			if(thursdayDayOld!=24 & thursdayDayOld!=25 & thursdayDayOld!=26 & thursdayDayOld!=27 & thursdayDayOld!=28 & thursdayDayOld!=29 & thursdayDayOld!=30)
				{
				thursdayDayNew = parseInt(thursdayDayOld,10) +7;
				thursdayMonthNew = thursdayMonthOld;
				thursdayYearNew = thursdayYearOld;
				}
			}
		if(thursdayMonthOld==02)
			{
			if(thursdayYearOld==2012 | thursdayYearOld==2016 | thursdayYearOld==2020 | thursdayYearOld==2024 | thursdayYearOld==2028 | thursdayYearOld==2032)
				{
				if(thursdayDayOld==29)
				{
				thursdayDayNew = 07;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==28)
				{
				thursdayDayNew = 06;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==27)
				{
				thursdayDayNew = 05;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==26)
				{
				thursdayDayNew = 04;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==25)
				{
				thursdayDayNew = 03;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==24)
				{
				thursdayDayNew = 02;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==23)
				{
				thursdayDayNew = 01;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld!=23 & thursdayDayOld!=24 & thursdayDayOld!=25 & thursdayDayOld!=26 & thursdayDayOld!=27 & thursdayDayOld!=28 & thursdayDayOld!=29)
					{
					thursdayDayNew = parseInt(thursdayDayOld,10) +7;
					thursdayMonthNew = thursdayMonthOld;
					thursdayYearNew = thursdayYearOld;
					}
				}
			if(thursdayYearOld!=2012 & thursdayYearOld!=2016 & thursdayYearOld!=2020 & thursdayYearOld!=2024 & thursdayYearOld!=2028 & thursdayYearOld!=2032)
				{
				if(thursdayDayOld==28)
				{
				thursdayDayNew = 07;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==27)
				{
				thursdayDayNew = 06;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==26)
				{
				thursdayDayNew = 05;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==25)
				{
				thursdayDayNew = 04;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==24)
				{
				thursdayDayNew = 03;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==23)
				{
				thursdayDayNew = 02;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld==22)
				{
				thursdayDayNew = 01;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)+1;
				}
				if(thursdayDayOld!=22 & thursdayDayOld!=23 & thursdayDayOld!=24 & thursdayDayOld!=25 & thursdayDayOld!=26 & thursdayDayOld!=27 & thursdayDayOld!=28)
					{
					thursdayDayNew = parseInt(thursdayDayOld,10) +7;
					thursdayMonthNew = thursdayMonthOld;
					thursdayYearNew = thursdayYearOld;
					}
				}
			}
		}
/*ADD 1 TO THE DAY OF FRIDAY*/	/* !!!!!!!!! STILL TO DO: ADJUST THAT DAYS JUMP 7 DAYS INSTEAD OF 1, CHECK OTHER DAYS FOR EXAMPLE */
		if(fridayDayOld>0 & fridayDayOld<32)
		{
		if(fridayMonthOld==01 | fridayMonthOld==03 | fridayMonthOld==05 | fridayMonthOld==07 | fridayMonthOld==08 | fridayMonthOld==10 | fridayMonthOld==12) //31 day month
			{
			if(fridayDayOld==31)
				{
				fridayDayNew = 07;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				if(fridayMonthNew==13)
					{
					fridayMonthNew=1;
					fridayYearNew= parseInt(fridayYearOld,10)+1;
					}
				}
			if(fridayDayOld==30)
			{
			fridayDayNew = 06;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			if(fridayMonthNew==13)
				{
				fridayMonthNew=1;
				fridayYearNew= parseInt(fridayYearOld,10)+1;
				}
			}
			if(fridayDayOld==29)
			{
			fridayDayNew = 05;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			if(fridayMonthNew==13)
				{
				fridayMonthNew=1;
				fridayYearNew= parseInt(fridayYearOld,10)+1;
				}
			}
			if(fridayDayOld==28)
			{
			fridayDayNew = 04;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			if(fridayMonthNew==13)
				{
				fridayMonthNew=1;
				fridayYearNew= parseInt(fridayYearOld,10)+1;
				}
			}
			if(fridayDayOld==27)
			{
			fridayDayNew = 03;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			if(fridayMonthNew==13)
				{
				fridayMonthNew=1;
				fridayYearNew= parseInt(fridayYearOld,10)+1;
				}
			}
			if(fridayDayOld==26)
			{
			fridayDayNew = 02;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			if(fridayMonthNew==13)
				{
				fridayMonthNew=1;
				fridayYearNew= parseInt(fridayYearOld,10)+1;
				}
			}
			if(fridayDayOld==25)
			{
			fridayDayNew = 01;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			if(fridayMonthNew==13)
				{
				fridayMonthNew=1;
				fridayYearNew= parseInt(fridayYearOld,10)+1;
				}
			}
			if(fridayDayOld!=25 & fridayDayOld!=26 & fridayDayOld!=27 & fridayDayOld!=28 & fridayDayOld!=29 & fridayDayOld!=30 & fridayDayOld!=31)
				{
				fridayDayNew = parseInt(fridayDayOld,10) +7; 
				fridayMonthNew = fridayMonthOld;
				fridayYearNew = fridayYearOld;
				}
			}
		if(fridayMonthOld==04 | fridayMonthOld==06 | fridayMonthOld==09 | fridayMonthOld==11 )//30 day month
			{
			if(fridayDayOld==30)
			{
			fridayDayNew = 07;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			}
			if(fridayDayOld==29)
			{
			fridayDayNew = 06;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			}
			if(fridayDayOld==28)
			{
			fridayDayNew = 05;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			}
			if(fridayDayOld==27)
			{
			fridayDayNew = 04;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			}
			if(fridayDayOld==26)
			{
			fridayDayNew = 03;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			}
			if(fridayDayOld==25)
			{
			fridayDayNew = 02;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			}
			if(fridayDayOld==24)
			{
			fridayDayNew = 01;
			fridayMonthNew = parseInt(fridayMonthOld,10)+1;
			}
			if(fridayDayOld!=24 & fridayDayOld!=25 & fridayDayOld!=26 & fridayDayOld!=27 & fridayDayOld!=28 & fridayDayOld!=29 & fridayDayOld!=30)
				{
				fridayDayNew = parseInt(fridayDayOld,10) +7;
				fridayMonthNew = fridayMonthOld;
				fridayYearNew = fridayYearOld;
				}
			}
		if(fridayMonthOld==02)
			{
			if(fridayYearOld==2012 | fridayYearOld==2016 | fridayYearOld==2020 | fridayYearOld==2024 | fridayYearOld==2028 | fridayYearOld==2032)
				{
				if(fridayDayOld==29)
				{
				fridayDayNew = 07;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==28)
				{
				fridayDayNew = 06;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==27)
				{
				fridayDayNew = 05;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==26)
				{
				fridayDayNew = 04;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==25)
				{
				fridayDayNew = 03;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==24)
				{
				fridayDayNew = 02;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==23)
				{
				fridayDayNew = 01;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld!=23 &fridayDayOld!=24 &fridayDayOld!=25 &fridayDayOld!=26 &fridayDayOld!=27 &fridayDayOld!=28 &fridayDayOld!=29)
					{
					fridayDayNew = parseInt(fridayDayOld,10) +7;
					fridayMonthNew = fridayMonthOld;
					fridayYearNew = fridayYearOld;
					}
				}
			if(fridayYearOld!=2012 & fridayYearOld!=2016 & fridayYearOld!=2020 & fridayYearOld!=2024 & fridayYearOld!=2028 & fridayYearOld!=2032)
				{
				if(fridayDayOld==28)
				{
				fridayDayNew = 07;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==27)
				{
				fridayDayNew = 06;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==26)
				{
				fridayDayNew = 05;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==25)
				{
				fridayDayNew = 04;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==24)
				{
				fridayDayNew = 03;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==23)
				{
				fridayDayNew = 02;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld==22)
				{
				fridayDayNew = 01;
				fridayMonthNew = parseInt(fridayMonthOld,10)+1;
				}
				if(fridayDayOld!=22 & fridayDayOld!=23 & fridayDayOld!=24 & fridayDayOld!=25 & fridayDayOld!=26 & fridayDayOld!=27 & fridayDayOld!=28)
					{
					fridayDayNew = parseInt(fridayDayOld,10) +7;
					fridayMonthNew = fridayMonthOld;
					fridayYearNew = fridayYearOld;
					}
				}
			}
		}
		
		/*ADD LEADING ZERO WHEN SINGULAR DIGIT*/
		if(mondayDayNew==1){mondayDayNew="01"}
		if(mondayDayNew==2){mondayDayNew="02"}
		if(mondayDayNew==3){mondayDayNew="03"}
		if(mondayDayNew==4){mondayDayNew="04"}
		if(mondayDayNew==5){mondayDayNew="05"}
		if(mondayDayNew==6){mondayDayNew="06"}
		if(mondayDayNew==7){mondayDayNew="07"}
		if(mondayDayNew==8){mondayDayNew="08"}
		if(mondayDayNew==9){mondayDayNew="09"}
		
		if(tuesdayDayNew==1){tuesdayDayNew="01"}
		if(tuesdayDayNew==2){tuesdayDayNew="02"}
		if(tuesdayDayNew==3){tuesdayDayNew="03"}
		if(tuesdayDayNew==4){tuesdayDayNew="04"}
		if(tuesdayDayNew==5){tuesdayDayNew="05"}
		if(tuesdayDayNew==6){tuesdayDayNew="06"}
		if(tuesdayDayNew==7){tuesdayDayNew="07"}
		if(tuesdayDayNew==8){tuesdayDayNew="08"}
		if(tuesdayDayNew==9){tuesdayDayNew="09"}
		
		if(wednesdayDayNew==1){wednesdayDayNew="01"}
		if(wednesdayDayNew==2){wednesdayDayNew="02"}
		if(wednesdayDayNew==3){wednesdayDayNew="03"}
		if(wednesdayDayNew==4){wednesdayDayNew="04"}
		if(wednesdayDayNew==5){wednesdayDayNew="05"}
		if(wednesdayDayNew==6){wednesdayDayNew="06"}
		if(wednesdayDayNew==7){wednesdayDayNew="07"}
		if(wednesdayDayNew==8){wednesdayDayNew="08"}
		if(wednesdayDayNew==9){wednesdayDayNew="09"}
		
		if(thursdayDayNew==1){thursdayDayNew="01"}
		if(thursdayDayNew==2){thursdayDayNew="02"}
		if(thursdayDayNew==3){thursdayDayNew="03"}
		if(thursdayDayNew==4){thursdayDayNew="04"}
		if(thursdayDayNew==5){thursdayDayNew="05"}
		if(thursdayDayNew==6){thursdayDayNew="06"}
		if(thursdayDayNew==7){thursdayDayNew="07"}
		if(thursdayDayNew==8){thursdayDayNew="08"}
		if(thursdayDayNew==9){thursdayDayNew="09"}
		
		if(fridayDayNew==1){fridayDayNew="01"}
		if(fridayDayNew==2){fridayDayNew="02"}
		if(fridayDayNew==3){fridayDayNew="03"}
		if(fridayDayNew==4){fridayDayNew="04"}
		if(fridayDayNew==5){fridayDayNew="05"}
		if(fridayDayNew==6){fridayDayNew="06"}
		if(fridayDayNew==7){fridayDayNew="07"}
		if(fridayDayNew==8){fridayDayNew="08"}
		if(fridayDayNew==9){fridayDayNew="09"}
		
		if(mondayMonthNew==1){mondayMonthNew="01"}
		if(mondayMonthNew==2){mondayMonthNew="02"}
		if(mondayMonthNew==3){mondayMonthNew="03"}
		if(mondayMonthNew==4){mondayMonthNew="04"}
		if(mondayMonthNew==5){mondayMonthNew="05"}
		if(mondayMonthNew==6){mondayMonthNew="06"}
		if(mondayMonthNew==7){mondayMonthNew="07"}
		if(mondayMonthNew==8){mondayMonthNew="08"}
		if(mondayMonthNew==9){mondayMonthNew="09"}
		
		if(tuesdayMonthNew==1){tuesdayMonthNew="01"}
		if(tuesdayMonthNew==2){tuesdayMonthNew="02"}
		if(tuesdayMonthNew==3){tuesdayMonthNew="03"}
		if(tuesdayMonthNew==4){tuesdayMonthNew="04"}
		if(tuesdayMonthNew==5){tuesdayMonthNew="05"}
		if(tuesdayMonthNew==6){tuesdayMonthNew="06"}
		if(tuesdayMonthNew==7){tuesdayMonthNew="07"}
		if(tuesdayMonthNew==8){tuesdayMonthNew="08"}
		if(tuesdayMonthNew==9){tuesdayMonthNew="09"}
		
		if(wednesdayMonthNew==1){wednesdayMonthNew="01"}
		if(wednesdayMonthNew==2){wednesdayMonthNew="02"}
		if(wednesdayMonthNew==3){wednesdayMonthNew="03"}
		if(wednesdayMonthNew==4){wednesdayMonthNew="04"}
		if(wednesdayMonthNew==5){wednesdayMonthNew="05"}
		if(wednesdayMonthNew==6){wednesdayMonthNew="06"}
		if(wednesdayMonthNew==7){wednesdayMonthNew="07"}
		if(wednesdayMonthNew==8){wednesdayMonthNew="08"}
		if(wednesdayMonthNew==9){wednesdayMonthNew="09"}
		
		if(thursdayMonthNew==1){thursdayMonthNew="01"}
		if(thursdayMonthNew==2){thursdayMonthNew="02"}
		if(thursdayMonthNew==3){thursdayMonthNew="03"}
		if(thursdayMonthNew==4){thursdayMonthNew="04"}
		if(thursdayMonthNew==5){thursdayMonthNew="05"}
		if(thursdayMonthNew==6){thursdayMonthNew="06"}
		if(thursdayMonthNew==7){thursdayMonthNew="07"}
		if(thursdayMonthNew==8){thursdayMonthNew="08"}
		if(thursdayMonthNew==9){thursdayMonthNew="09"}
		
		if(fridayMonthNew==1){fridayMonthNew="01"}
		if(fridayMonthNew==2){fridayMonthNew="02"}
		if(fridayMonthNew==3){fridayMonthNew="03"}
		if(fridayMonthNew==4){fridayMonthNew="04"}
		if(fridayMonthNew==5){fridayMonthNew="05"}
		if(fridayMonthNew==6){fridayMonthNew="06"}
		if(fridayMonthNew==7){fridayMonthNew="07"}
		if(fridayMonthNew==8){fridayMonthNew="08"}
		if(fridayMonthNew==9){fridayMonthNew="09"}
				
		$("#mondayDate").text(mondayDayNew+"/"+mondayMonthNew+"/"+mondayYearNew)
		$("#tuesdayDate").text(tuesdayDayNew+"/"+tuesdayMonthNew+"/"+tuesdayYearNew)
		$("#wednesdayDate").text(wednesdayDayNew+"/"+wednesdayMonthNew+"/"+wednesdayYearNew)
		$("#thursdayDate").text(thursdayDayNew+"/"+thursdayMonthNew+"/"+thursdayYearNew)
		$("#fridayDate").text(fridayDayNew+"/"+fridayMonthNew+"/"+fridayYearNew)	
		
		positionAllActivities(1);
		
		}//close Else loop that started all the way in the beginning of this function
	});
	$("#vorigeWeek").click(function(event){
		event.preventDefault();
		//Pas de week aan//
		var str = $("#theScheduledWeek").text();
		var oudeweek = parseInt(str.substr(5,2));
		if(oudeweek == 1){}
		else{
		var nieuweweek = oudeweek - 1;
		$("#theScheduledWeek").text("Week "+nieuweweek);
		//Pas de data van de week aan//
		var mondayDate = $("#mondayDate").text();
		var tuesdayDate = $("#tuesdayDate").text();
		var wednesdayDate = $("#wednesdayDate").text();
		var thursdayDate = $("#thursdayDate").text();
		var fridayDate = $("#fridayDate").text();
		
		var mondayDayOld = mondayDate.substr(0,2);
		var mondayMonthOld = mondayDate.substr(3,2);
		var mondayYearOld = mondayDate.substr(6,4);
		
		var tuesdayDayOld = tuesdayDate.substr(0,2);
		var tuesdayMonthOld = tuesdayDate.substr(3,2);
		var tuesdayYearOld = tuesdayDate.substr(6,4);
		
		var wednesdayDayOld = wednesdayDate.substr(0,2);
		var wednesdayMonthOld = wednesdayDate.substr(3,2);
		var wednesdayYearOld = wednesdayDate.substr(6,4);
		
		var thursdayDayOld = thursdayDate.substr(0,2);
		var thursdayMonthOld = thursdayDate.substr(3,2);
		var thursdayYearOld = thursdayDate.substr(6,4);
		
		var fridayDayOld = fridayDate.substr(0,2);
		var fridayMonthOld = fridayDate.substr(3,2);
		var fridayYearOld = fridayDate.substr(6,4);
/*INITIALISATION OF VARIABLES*/	
		var mondayDayNew = 1;
		var tuesdayDayNew = 1;
		var wednesdayDayNew = 1;
		var thursdayDayNew = 1;
		var fridayDayNew = 1;
		var mondayMonthNew = 1;
		var tuesdayMonthNew = 1;
		var wednesdayMonthNew = 1;
		var thursdayMonthNew = 1;
		var fridayMonthNew = 1;
		var mondayYearNew = mondayYearOld;
		var tuesdayYearNew = tuesdayYearOld;
		var wednesdayYearNew = wednesdayYearOld;
		var thursdayYearNew = thursdayYearOld;
		var fridayYearNew = fridayYearOld;
/*ADD 1 TO THE DAY OF MONDAY*/		
		/*IMPORTANT REMARK: THE METHOD PARSEINT(X) PARSES STRINGS TO INTEGERS USING THE OCTADECIMAL BASE, BECAUSE FOR EXAMPLE: 08 AND 09 DO NOT EXIST IN OCTADECIMAL FORM, IT RETURNS 0 FOR THESE INSTEAD OF THE EXPECTED 8 AND 9!, USE PARSEINT(X,10) TO SPECIFY BASE 10 USAGE */
		if(mondayDayOld>0 & mondayDayOld<32)
			{
			if(mondayMonthOld==02 | mondayMonthOld==04 | mondayMonthOld==06 | mondayMonthOld==08 | mondayMonthOld==09 | mondayMonthOld==11 | mondayMonthOld==01) //31 day month before current month
				{
				if(mondayDayOld==07)
					{
					mondayDayNew = 31;
					mondayMonthNew = parseInt(mondayMonthOld,10)-1;
					if(mondayMonthNew==0)
						{
						mondayMonthNew=12;
						mondayYearNew= parseInt(mondayYearOld,10)-1;
						}
					}
				if(mondayDayOld==06)
				{
				mondayDayNew = 30;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				if(mondayMonthNew==0)
					{
					mondayMonthNew=12;
					mondayYearNew= parseInt(mondayYearOld,10)-1;
					}
				}
				if(mondayDayOld==05)
				{
				mondayDayNew = 29;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				if(mondayMonthNew==0)
					{
					mondayMonthNew=12;
					mondayYearNew= parseInt(mondayYearOld,10)-1;
					}
				}
				if(mondayDayOld==04)
				{
				mondayDayNew = 28;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				if(mondayMonthNew==0)
					{
					mondayMonthNew=12;
					mondayYearNew= parseInt(mondayYearOld,10)-1;
					}
				}
				if(mondayDayOld==03)
				{
				mondayDayNew = 27;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				if(mondayMonthNew==0)
					{
					mondayMonthNew=12;
					mondayYearNew= parseInt(mondayYearOld,10)-1;
					}
				}
				if(mondayDayOld==02)
				{
				mondayDayNew = 26;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				if(mondayMonthNew==0)
					{
					mondayMonthNew=12;
					mondayYearNew= parseInt(mondayYearOld,10)-1;
					}
				}
				if(mondayDayOld==01)
				{
				mondayDayNew = 25;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				if(mondayMonthNew==0)
					{
					mondayMonthNew=12;
					mondayYearNew= parseInt(mondayYearOld,10)-1;
					}
				}
				if(mondayDayOld!=07 & mondayDayOld!=06 & mondayDayOld!=05 & mondayDayOld!=04 & mondayDayOld!=03 & mondayDayOld!=02 & mondayDayOld!=01)
					{
					mondayDayNew = parseInt(mondayDayOld,10)-7;
					mondayMonthNew = mondayMonthOld;
					mondayYearNew = mondayYearOld;
					}
				}
			if(mondayMonthOld==05 | mondayMonthOld==07 | mondayMonthOld==10 | mondayMonthOld==12 )//30 day month before current month
				{
				if(mondayDayOld==07)
				{
				mondayDayNew = 30;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				}
				if(mondayDayOld==06)
				{
				mondayDayNew = 29;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				}
				if(mondayDayOld==05)
				{
				mondayDayNew = 28;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				}
				if(mondayDayOld==04)
				{
				mondayDayNew = 27;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				}
				if(mondayDayOld==03)
				{
				mondayDayNew = 26;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				}
				if(mondayDayOld==02)
				{
				mondayDayNew = 25;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				}
				if(mondayDayOld==01)
				{
				mondayDayNew = 24;
				mondayMonthNew = parseInt(mondayMonthOld,10)-1;
				}
				if(mondayDayOld!=07 & mondayDayOld!=06 & mondayDayOld!=05 & mondayDayOld!=04 & mondayDayOld!=03 & mondayDayOld!=02 & mondayDayOld!=01)
					{
					mondayDayNew = parseInt(mondayDayOld,10)-7;
					mondayMonthNew = mondayMonthOld;
					mondayYearNew = mondayYearOld;
					}
				}
			if(mondayMonthOld==03)
				{
				if(mondayYearOld==2012 | mondayYearOld==2016 | mondayYearOld==2020 | mondayYearOld==2024 | mondayYearOld==2028 | mondayYearOld==2032)
					{
					if(mondayDayOld==07)
					{
					mondayDayNew = 29;
					mondayMonthNew = parseInt(mondayMonthOld,10)-1;
					}
					if(mondayDayOld==06)
					{
					mondayDayNew = 28;
					mondayMonthNew = parseInt(mondayMonthOld,10)-1;
					}
					if(mondayDayOld==05)
					{
					mondayDayNew = 27;
					mondayMonthNew = parseInt(mondayMonthOld,10)-1;
					}
					if(mondayDayOld==04)
					{
					mondayDayNew = 26;
					mondayMonthNew = parseInt(mondayMonthOld,10)-1;
					}
					if(mondayDayOld==03)
					{
					mondayDayNew = 25;
					mondayMonthNew = parseInt(mondayMonthOld,10)-1;
					}
					if(mondayDayOld==02)
					{
					mondayDayNew = 24;
					mondayMonthNew = parseInt(mondayMonthOld,10)-1;
					}
					if(mondayDayOld==01)
					{
					mondayDayNew = 23;
					mondayMonthNew = parseInt(mondayMonthOld,10)-1;
					}
					if( mondayDayOld!=07 & mondayDayOld!=06 & mondayDayOld!=05 & mondayDayOld!=04 & mondayDayOld!=03 & mondayDayOld!=02 & mondayDayOld!=01)
						{
						mondayDayNew = parseInt(mondayDayOld,10)-7;
						mondayMonthNew = mondayMonthOld;
						mondayYearNew = mondayYearOld;
						}
					}
				if(mondayYearOld!=2012 & mondayYearOld!=2016 & mondayYearOld!=2020 & mondayYearOld!=2024 & mondayYearOld!=2028 & mondayYearOld!=2032)
					{
					if(mondayDayOld==07)
						{
						mondayDayNew = 28;
						mondayMonthNew = parseInt(mondayMonthOld,10)-1;
						}
					if(mondayDayOld==06)
						{
						mondayDayNew = 27;
						mondayMonthNew = parseInt(mondayMonthOld,10)-1;
						}
					if(mondayDayOld==05)
						{
						mondayDayNew = 26;
						mondayMonthNew = parseInt(mondayMonthOld,10)-1;
						}
					if(mondayDayOld==04)
						{
						mondayDayNew = 25;
						mondayMonthNew = parseInt(mondayMonthOld,10)-1;
						}
					if(mondayDayOld==03)
						{
						mondayDayNew = 24;
						mondayMonthNew = parseInt(mondayMonthOld,10)-1;
						}
					if(mondayDayOld==02)
						{
						mondayDayNew = 23;
						mondayMonthNew = parseInt(mondayMonthOld,10)-1;
						}
					if(mondayDayOld==01)
						{
						mondayDayNew = 22;
						mondayMonthNew = parseInt(mondayMonthOld,10)-1;
						}
					if(mondayDayOld!=07 & mondayDayOld!=06 & mondayDayOld!=05 & mondayDayOld!=04 & mondayDayOld!=03 & mondayDayOld!=02 & mondayDayOld!=01)
						{
						mondayDayNew = parseInt(mondayDayOld,10) -7;
						mondayMonthNew = mondayMonthOld;
						mondayYearNew = mondayYearOld;
						}
					}
				}
			}
/*ADD 1 TO THE DAY OF TUESDAY*/	
		if(tuesdayDayOld>0 & tuesdayDayOld<32)
		{
		if(tuesdayMonthOld==02 | tuesdayMonthOld==04 | tuesdayMonthOld==06 | tuesdayMonthOld==08 | tuesdayMonthOld==09 | tuesdayMonthOld==11 | tuesdayMonthOld==01) //31 day month before current month
			{
			if(tuesdayDayOld==07)
				{
				tuesdayDayNew = 31;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				if(tuesdayMonthNew==0)
					{
					tuesdayMonthNew=12;
					tuesdayYearNew= parseInt(tuesdayYearOld,10)-1;
					}
				}
			if(tuesdayDayOld==06)
			{
			tuesdayDayNew = 30;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
			if(tuesdayMonthNew==0)
				{
				tuesdayMonthNew=12;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)-1;
				}
			}
			if(tuesdayDayOld==05)
			{
			tuesdayDayNew = 29;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
			if(tuesdayMonthNew==0)
				{
				tuesdayMonthNew=12;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)-1;
				}
			}
			if(tuesdayDayOld==04)
			{
			tuesdayDayNew = 28;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
			if(tuesdayMonthNew==0)
				{
				tuesdayMonthNew=12;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)-1;
				}
			}
			if(tuesdayDayOld==03)
			{
			tuesdayDayNew = 27;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
			if(tuesdayMonthNew==0)
				{
				tuesdayMonthNew=12;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)-1;
				}
			}
			if(tuesdayDayOld==02)
			{
			tuesdayDayNew = 26;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
			if(tuesdayMonthNew==0)
				{
				tuesdayMonthNew=12;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)-1;
				}
			}
			if(tuesdayDayOld==01)
			{
			tuesdayDayNew = 25;
			tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
			if(tuesdayMonthNew==0)
				{
				tuesdayMonthNew=12;
				tuesdayYearNew= parseInt(tuesdayYearOld,10)-1;
				}
			}
			if(tuesdayDayOld!=07 & tuesdayDayOld!=06 & tuesdayDayOld!=05 & tuesdayDayOld!=04 & tuesdayDayOld!=03 & tuesdayDayOld!=02 & tuesdayDayOld!=01)
				{
				tuesdayDayNew = parseInt(tuesdayDayOld,10) -7; 
				tuesdayMonthNew = tuesdayMonthOld;
				tuesdayYearNew = tuesdayYearOld;
				}
			}
		if(tuesdayMonthOld==05 | tuesdayMonthOld==07 | tuesdayMonthOld==10 | tuesdayMonthOld==12 )//30 day month before current month
			{
		if(tuesdayDayOld==07)
		{
		tuesdayDayNew = 30;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
		}
		if(tuesdayDayOld==06)
		{
		tuesdayDayNew = 29;		
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
		}
		if(tuesdayDayOld==05)
		{
		tuesdayDayNew = 28;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
		}
		if(tuesdayDayOld==04)
		{
		tuesdayDayNew = 27;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
		}
		if(tuesdayDayOld==03)
		{
		tuesdayDayNew = 26;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
		}
		if(tuesdayDayOld==02)
		{
		tuesdayDayNew = 25;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
		}
		if(tuesdayDayOld==01)
		{
		tuesdayDayNew = 24;
		tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
		}
		if(tuesdayDayOld!=07 & tuesdayDayOld!=06 & tuesdayDayOld!=05 & tuesdayDayOld!=04 & tuesdayDayOld!=03 & tuesdayDayOld!=02 & tuesdayDayOld!=01)
				{
				tuesdayDayNew = parseInt(tuesdayDayOld,10) -7;
				tuesdayMonthNew = tuesdayMonthOld;
				tuesdayYearNew = tuesdayYearOld;
				}
			}
		if(tuesdayMonthOld==03)
			{
			if(tuesdayYearOld==2012 | tuesdayYearOld==2016 | tuesdayYearOld==2020 | tuesdayYearOld==2024 | tuesdayYearOld==2028 | tuesdayYearOld==2032)
				{
				if(tuesdayDayOld==07)
				{
				tuesdayDayNew = 29;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==06)
				{
				tuesdayDayNew = 28;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==05)
				{
				tuesdayDayNew = 27;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==04)
				{
				tuesdayDayNew = 26;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==03)
				{
				tuesdayDayNew = 25;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==02)
				{
				tuesdayDayNew = 24;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==01)
				{
				tuesdayDayNew = 23;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld!=07 & tuesdayDayOld!=06 & tuesdayDayOld!=05 & tuesdayDayOld!=04 & tuesdayDayOld!=03 & tuesdayDayOld!=02 & tuesdayDayOld!=01)
					{
					tuesdayDayNew = parseInt(tuesdayDayOld,10) -7;
					tuesdayMonthNew = tuesdayMonthOld;
					tuesdayYearNew = tuesdayYearOld;
					}
				}
			if(tuesdayYearOld!=2012 & tuesdayYearOld!=2016 & tuesdayYearOld!=2020 & tuesdayYearOld!=2024 & tuesdayYearOld!=2028 & tuesdayYearOld!=2032)
				{
				if(tuesdayDayOld==07)
				{
				tuesdayDayNew = 28;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==06)
				{
				tuesdayDayNew = 27;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==05)
				{
				tuesdayDayNew = 26;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==04)
				{
				tuesdayDayNew = 25;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==03)
				{
				tuesdayDayNew = 24;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==02)
				{
				tuesdayDayNew = 23;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld==01)
				{
				tuesdayDayNew = 22;
				tuesdayMonthNew = parseInt(tuesdayMonthOld,10)-1;
				}
				if(tuesdayDayOld!=07 & tuesdayDayOld!=06 & tuesdayDayOld!=05 & tuesdayDayOld!=04 & tuesdayDayOld!=03 & tuesdayDayOld!=02 & tuesdayDayOld!=01)
					{
					tuesdayDayNew = parseInt(tuesdayDayOld,10) -7;
					tuesdayMonthNew = tuesdayMonthOld;
					tuesdayYearNew = tuesdayYearOld;
					}
				}
			}
		}
/*ADD 1 TO THE DAY OF WEDNESDAY*/	
		if(wednesdayDayOld>0 & wednesdayDayOld<32)
		{
		if(wednesdayMonthOld==02 | wednesdayMonthOld==04 | wednesdayMonthOld==06 | wednesdayMonthOld==08 | wednesdayMonthOld==09 | wednesdayMonthOld==11 | wednesdayMonthOld==01) //31 day month
			{
			if(wednesdayDayOld==07)
				{
				wednesdayDayNew = 31;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				if(wednesdayMonthNew==0)
					{
					wednesdayMonthNew=12;
					wednesdayYearNew= parseInt(wednesdayYearOld,10)-1;
					}
				}
			if(wednesdayDayOld==06)
			{
			wednesdayDayNew = 30;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			if(wednesdayMonthNew==0)
				{
				wednesdayMonthNew=12;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)-1;
				}
			}
			if(wednesdayDayOld==05)
			{
			wednesdayDayNew = 29;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			if(wednesdayMonthNew==0)
				{
				wednesdayMonthNew=12;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)-1;
				}
			}
			if(wednesdayDayOld==04)
			{
			wednesdayDayNew = 28;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			if(wednesdayMonthNew==0)
				{
				wednesdayMonthNew=12;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)-1;
				}
			}
			if(wednesdayDayOld==03)
			{
			wednesdayDayNew = 27;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			if(wednesdayMonthNew==0)
				{
				wednesdayMonthNew=12;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)-1;
				}
			}
			if(wednesdayDayOld==02)
			{
			wednesdayDayNew = 26;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			if(wednesdayMonthNew==0)
				{
				wednesdayMonthNew=12;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)-1;
				}
			}
			if(wednesdayDayOld==01)
			{
			wednesdayDayNew = 25;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			if(wednesdayMonthNew==0)
				{
				wednesdayMonthNew=12;
				wednesdayYearNew= parseInt(wednesdayYearOld,10)-1;
				}
			}
			if(wednesdayDayOld!=07 & wednesdayDayOld!=06 & wednesdayDayOld!=05 & wednesdayDayOld!=04 & wednesdayDayOld!=03 & wednesdayDayOld!=02 & wednesdayDayOld!=01)
				{
				wednesdayDayNew = parseInt(wednesdayDayOld,10) -7; 
				wednesdayMonthNew = wednesdayMonthOld;
				wednesdayYearNew = wednesdayYearOld;
				}
			}
		if(wednesdayMonthOld==05 | wednesdayMonthOld==07 | wednesdayMonthOld==10 | wednesdayMonthOld==12 )//30 day month before current month
			{
			if(wednesdayDayOld==07)
			{
			wednesdayDayNew = 30;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			}
			if(wednesdayDayOld==06)
			{
			wednesdayDayNew = 29;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			}
			if(wednesdayDayOld==05)
			{
			wednesdayDayNew = 28;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			}
			if(wednesdayDayOld==04)
			{
			wednesdayDayNew = 27;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			}
			if(wednesdayDayOld==03)
			{
			wednesdayDayNew = 26;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			}
			if(wednesdayDayOld==02)
			{
			wednesdayDayNew = 25;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			}
			if(wednesdayDayOld==01)
			{
			wednesdayDayNew = 24;
			wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
			}
			if(wednesdayDayOld!=07 & wednesdayDayOld!=06 & wednesdayDayOld!=05 & wednesdayDayOld!=04 & wednesdayDayOld!=03 & wednesdayDayOld!=02 & wednesdayDayOld!=01)
				{
				wednesdayDayNew = parseInt(wednesdayDayOld,10) -7;
				wednesdayMonthNew = wednesdayMonthOld;
				wednesdayYearNew = wednesdayYearOld;
				}
			}
		if(wednesdayMonthOld==03)
			{
			if(wednesdayYearOld==2012 | wednesdayYearOld==2016 | wednesdayYearOld==2020 | wednesdayYearOld==2024 | wednesdayYearOld==2028 | wednesdayYearOld==2032)
				{
				if(wednesdayDayOld==07)
				{
				wednesdayDayNew = 29;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==06)
				{
				wednesdayDayNew = 28;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==05)
				{
				wednesdayDayNew = 27;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==04)
				{
				wednesdayDayNew = 26;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==03)
				{
				wednesdayDayNew = 25;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==02)
				{
				wednesdayDayNew = 24;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==04)
				{
				wednesdayDayNew = 23;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld!=07 & wednesdayDayOld!=06 & wednesdayDayOld!=05 & wednesdayDayOld!=04 & wednesdayDayOld!=03 & wednesdayDayOld!=02 & wednesdayDayOld!=01)
					{
					wednesdayDayNew = parseInt(wednesdayDayOld,10) -7;
					wednesdayMonthNew = wednesdayMonthOld;
					wednesdayYearNew = wednesdayYearOld;
					}
				}
			if(wednesdayYearOld!=2012 & wednesdayYearOld!=2016 & wednesdayYearOld!=2020 & wednesdayYearOld!=2024 & wednesdayYearOld!=2028 & wednesdayYearOld!=2032)
				{
				if(wednesdayDayOld==07)
				{
				wednesdayDayNew = 28;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==06)
				{
				wednesdayDayNew = 27;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==05)
				{
				wednesdayDayNew = 26;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==04)
				{
				wednesdayDayNew = 25;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==03)
				{
				wednesdayDayNew = 24;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==02)
				{
				wednesdayDayNew = 23;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld==01)
				{
				wednesdayDayNew = 22;
				wednesdayMonthNew = parseInt(wednesdayMonthOld,10)-1;
				}
				if(wednesdayDayOld!=07 & wednesdayDayOld!=06 & wednesdayDayOld!=05 & wednesdayDayOld!=04 & wednesdayDayOld!=03 & wednesdayDayOld!=02 & wednesdayDayOld!=01)
					{
					wednesdayDayNew = parseInt(wednesdayDayOld,10) -7;
					wednesdayMonthNew = wednesdayMonthOld;
					wednesdayYearNew = wednesdayYearOld;
					}
				}
			}
		}
/*ADD 1 TO THE DAY OF THURSDAY*/	
		if(thursdayDayOld>0 & thursdayDayOld<32)
		{
		if(thursdayMonthOld==02 | thursdayMonthOld==04 | thursdayMonthOld==06 | thursdayMonthOld==08 | thursdayMonthOld==09 | thursdayMonthOld==11 | thursdayMonthOld==01) //31 day month before current month
			{
			if(thursdayDayOld==07)
				{
				thursdayDayNew = 31;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				if(thursdayMonthNew==0)
					{
					thursdayMonthNew=12;
					thursdayYearNew= parseInt(thursdayYearOld,10)-1;
					}
				}
			if(thursdayDayOld==06)
			{
			thursdayDayNew = 30;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			if(thursdayMonthNew==0)
				{
				thursdayMonthNew=12;
				thursdayYearNew= parseInt(thursdayYearOld,10)-1;
				}
			}
			if(thursdayDayOld==05)
			{
			thursdayDayNew = 29;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			if(thursdayMonthNew==0)
				{
				thursdayMonthNew=12;
				thursdayYearNew= parseInt(thursdayYearOld,10)-1;
				}
			}
			if(thursdayDayOld==04)
			{
			thursdayDayNew = 28;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			if(thursdayMonthNew==0)
				{
				thursdayMonthNew=12;
				thursdayYearNew= parseInt(thursdayYearOld,10)-1;
				}
			}
			if(thursdayDayOld==03)
			{
			thursdayDayNew = 27;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			if(thursdayMonthNew==0)
				{
				thursdayMonthNew=12;
				thursdayYearNew= parseInt(thursdayYearOld,10)-1;
				}
			}
			if(thursdayDayOld==02)
			{
			thursdayDayNew = 26;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			if(thursdayMonthNew==0)
				{
				thursdayMonthNew=12;
				thursdayYearNew= parseInt(thursdayYearOld,10)-1;
				}
			}
			if(thursdayDayOld==01)
			{
			thursdayDayNew = 25;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			if(thursdayMonthNew==0)
				{
				thursdayMonthNew=12;
				thursdayYearNew= parseInt(thursdayYearOld,10)-1;
				}
			}
			if(thursdayDayOld!=07 & thursdayDayOld!=06 & thursdayDayOld!=05 & thursdayDayOld!=04 & thursdayDayOld!=03 & thursdayDayOld!=02 & thursdayDayOld!=01)
				{
				thursdayDayNew = parseInt(thursdayDayOld,10) -7; 
				thursdayMonthNew = thursdayMonthOld;
				thursdayYearNew = thursdayYearOld;
				}
			}
		if(thursdayMonthOld==05 | thursdayMonthOld==07 | thursdayMonthOld==10 | thursdayMonthOld==12 )//30 day month
			{
			if(thursdayDayOld==07)
			{
			thursdayDayNew = 30;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			}
			if(thursdayDayOld==06)
			{
			thursdayDayNew = 29;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			}
			if(thursdayDayOld==05)
			{
			thursdayDayNew = 28;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			}
			if(thursdayDayOld==04)
			{
			thursdayDayNew = 27;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			}
			if(thursdayDayOld==03)
			{
			thursdayDayNew = 26;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			}
			if(thursdayDayOld==02)
			{
			thursdayDayNew = 25;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			}
			if(thursdayDayOld==01)
			{
			thursdayDayNew = 24;
			thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
			}
			if(thursdayDayOld!=07 & thursdayDayOld!=06 & thursdayDayOld!=05 & thursdayDayOld!=04 & thursdayDayOld!=03 & thursdayDayOld!=02 & thursdayDayOld!=01)
				{
				thursdayDayNew = parseInt(thursdayDayOld,10) -7;
				thursdayMonthNew = thursdayMonthOld;
				thursdayYearNew = thursdayYearOld;
				}
			}
		if(thursdayMonthOld==03)
			{
			if(thursdayYearOld==2012 | thursdayYearOld==2016 | thursdayYearOld==2020 | thursdayYearOld==2024 | thursdayYearOld==2028 | thursdayYearOld==2032)
				{
				if(thursdayDayOld==07)
				{
				thursdayDayNew = 29;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==06)
				{
				thursdayDayNew = 28;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==05)
				{
				thursdayDayNew = 27;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==04)
				{
				thursdayDayNew = 26;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==03)
				{
				thursdayDayNew = 25;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==02)
				{
				thursdayDayNew = 24;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==01)
				{
				thursdayDayNew = 23;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld!=07 & thursdayDayOld!=06 & thursdayDayOld!=05 & thursdayDayOld!=04 & thursdayDayOld!=03 & thursdayDayOld!=02 & thursdayDayOld!=01)
					{
					thursdayDayNew = parseInt(thursdayDayOld,10) -7;
					thursdayMonthNew = thursdayMonthOld;
					thursdayYearNew = thursdayYearOld;
					}
				}
			if(thursdayYearOld!=2012 & thursdayYearOld!=2016 & thursdayYearOld!=2020 & thursdayYearOld!=2024 & thursdayYearOld!=2028 & thursdayYearOld!=2032)
				{
				if(thursdayDayOld==07)
				{
				thursdayDayNew = 28;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==06)
				{
				thursdayDayNew = 27;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==05)
				{
				thursdayDayNew = 26;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==04)
				{
				thursdayDayNew = 25;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==03)
				{
				thursdayDayNew = 24;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==02)
				{
				thursdayDayNew = 23;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld==01)
				{
				thursdayDayNew = 22;
				thursdayMonthNew = parseInt(thursdayMonthOld,10)-1;
				}
				if(thursdayDayOld!=07 & thursdayDayOld!=06 & thursdayDayOld!=05 & thursdayDayOld!=04 & thursdayDayOld!=03 & thursdayDayOld!=02 & thursdayDayOld!=01)
					{
					thursdayDayNew = parseInt(thursdayDayOld,10) -7;
					thursdayMonthNew = thursdayMonthOld;
					thursdayYearNew = thursdayYearOld;
					}
				}
			}
		}
/*ADD 1 TO THE DAY OF FRIDAY*/	/* !!!!!!!!! STILL TO DO: ADJUST THAT DAYS JUMP 7 DAYS INSTEAD OF 1, CHECK OTHER DAYS FOR EXAMPLE */
		if(fridayDayOld>0 & fridayDayOld<32)
		{
		if(fridayMonthOld==02 | fridayMonthOld==04 | fridayMonthOld==06 | fridayMonthOld==08 | fridayMonthOld==09 | fridayMonthOld==11 | fridayMonthOld==01) //31 day month before current month
			{
			if(fridayDayOld==07)
				{
				fridayDayNew = 31;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				if(fridayMonthNew==0)
					{
					fridayMonthNew=12;
					fridayYearNew= parseInt(fridayYearOld,10)-1;
					}
				}
			if(fridayDayOld==06)
			{
			fridayDayNew = 30;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			if(fridayMonthNew==0)
				{
				fridayMonthNew=12;
				fridayYearNew= parseInt(fridayYearOld,10)-1;
				}
			}
			if(fridayDayOld==05)
			{
			fridayDayNew = 29;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			if(fridayMonthNew==0)
				{
				fridayMonthNew=12;
				fridayYearNew= parseInt(fridayYearOld,10)-1;
				}
			}
			if(fridayDayOld==04)
			{
			fridayDayNew = 28;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			if(fridayMonthNew==0)
				{
				fridayMonthNew=12;
				fridayYearNew= parseInt(fridayYearOld,10)-1;
				}
			}
			if(fridayDayOld==03)
			{
			fridayDayNew = 27;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			if(fridayMonthNew==0)
				{
				fridayMonthNew=12;
				fridayYearNew= parseInt(fridayYearOld,10)-1;
				}
			}
			if(fridayDayOld==02)
			{
			fridayDayNew = 26;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			if(fridayMonthNew==0)
				{
				fridayMonthNew=12;
				fridayYearNew= parseInt(fridayYearOld,10)-1;
				}
			}
			if(fridayDayOld==01)
			{
			fridayDayNew = 25;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			if(fridayMonthNew==0)
				{
				fridayMonthNew=12;
				fridayYearNew= parseInt(fridayYearOld,10)-1;
				}
			}
			if(fridayDayOld!=07 & fridayDayOld!=06 & fridayDayOld!=05 & fridayDayOld!=04 & fridayDayOld!=03 & fridayDayOld!=02 & fridayDayOld!=01)
				{
				fridayDayNew = parseInt(fridayDayOld,10) -7; 
				fridayMonthNew = fridayMonthOld;
				fridayYearNew = fridayYearOld;
				}
			}
		if(fridayMonthOld==05 | fridayMonthOld==07 | fridayMonthOld==10 | fridayMonthOld==12 )//30 day month before current month
			{
			if(fridayDayOld==07)
			{
			fridayDayNew = 30;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			}
			if(fridayDayOld==06)
			{
			fridayDayNew = 29;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			}
			if(fridayDayOld==05)
			{
			fridayDayNew = 28;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			}
			if(fridayDayOld==04)
			{
			fridayDayNew = 27;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			}
			if(fridayDayOld==03)
			{
			fridayDayNew = 26;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			}
			if(fridayDayOld==02)
			{
			fridayDayNew = 25;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			}
			if(fridayDayOld==01)
			{
			fridayDayNew = 24;
			fridayMonthNew = parseInt(fridayMonthOld,10)-1;
			}
			if(fridayDayOld!=07 & fridayDayOld!=06 & fridayDayOld!=05 & fridayDayOld!=04 & fridayDayOld!=03 & fridayDayOld!=02 & fridayDayOld!=01)
				{
				fridayDayNew = parseInt(fridayDayOld,10) -7;
				fridayMonthNew = fridayMonthOld;
				fridayYearNew = fridayYearOld;
				}
			}
		if(fridayMonthOld==03)
			{
			if(fridayYearOld==2012 | fridayYearOld==2016 | fridayYearOld==2020 | fridayYearOld==2024 | fridayYearOld==2028 | fridayYearOld==2032)
				{
				if(fridayDayOld==07)
				{
				fridayDayNew = 29;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==06)
				{
				fridayDayNew = 28;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==05)
				{
				fridayDayNew = 27;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==04)
				{
				fridayDayNew = 26;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==03)
				{
				fridayDayNew = 25;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==02)
				{
				fridayDayNew = 24;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==01)
				{
				fridayDayNew = 23;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld!=07 & fridayDayOld!=06 & fridayDayOld!=05 & fridayDayOld!=04 & fridayDayOld!=03 & fridayDayOld!=02 & fridayDayOld!=01)
					{
					fridayDayNew = parseInt(fridayDayOld,10) -7;
					fridayMonthNew = fridayMonthOld;
					fridayYearNew = fridayYearOld;
					}
				}
			if(fridayYearOld!=2012 & fridayYearOld!=2016 & fridayYearOld!=2020 & fridayYearOld!=2024 & fridayYearOld!=2028 & fridayYearOld!=2032)
				{
				if(fridayDayOld==07)
				{
				fridayDayNew = 28;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==06)
				{
				fridayDayNew = 27;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==05)
				{
				fridayDayNew = 26;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==04)
				{
				fridayDayNew = 25;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==03)
				{
				fridayDayNew = 24;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==02)
				{
				fridayDayNew = 23;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld==01)
				{
				fridayDayNew = 22;
				fridayMonthNew = parseInt(fridayMonthOld,10)-1;
				}
				if(fridayDayOld!=07 & fridayDayOld!=06 & fridayDayOld!=05 & fridayDayOld!=04 & fridayDayOld!=03 & fridayDayOld!=02 & fridayDayOld!=01)
					{
					fridayDayNew = parseInt(fridayDayOld,10) -7;
					fridayMonthNew = fridayMonthOld;
					fridayYearNew = fridayYearOld;
					}
				}
			}
		}
		
		/*ADD LEADING ZERO WHEN SINGULAR DIGIT*/
		if(mondayDayNew==1){mondayDayNew="01"}
		if(mondayDayNew==2){mondayDayNew="02"}
		if(mondayDayNew==3){mondayDayNew="03"}
		if(mondayDayNew==4){mondayDayNew="04"}
		if(mondayDayNew==5){mondayDayNew="05"}
		if(mondayDayNew==6){mondayDayNew="06"}
		if(mondayDayNew==7){mondayDayNew="07"}
		if(mondayDayNew==8){mondayDayNew="08"}
		if(mondayDayNew==9){mondayDayNew="09"}
		
		if(tuesdayDayNew==1){tuesdayDayNew="01"}
		if(tuesdayDayNew==2){tuesdayDayNew="02"}
		if(tuesdayDayNew==3){tuesdayDayNew="03"}
		if(tuesdayDayNew==4){tuesdayDayNew="04"}
		if(tuesdayDayNew==5){tuesdayDayNew="05"}
		if(tuesdayDayNew==6){tuesdayDayNew="06"}
		if(tuesdayDayNew==7){tuesdayDayNew="07"}
		if(tuesdayDayNew==8){tuesdayDayNew="08"}
		if(tuesdayDayNew==9){tuesdayDayNew="09"}
		
		if(wednesdayDayNew==1){wednesdayDayNew="01"}
		if(wednesdayDayNew==2){wednesdayDayNew="02"}
		if(wednesdayDayNew==3){wednesdayDayNew="03"}
		if(wednesdayDayNew==4){wednesdayDayNew="04"}
		if(wednesdayDayNew==5){wednesdayDayNew="05"}
		if(wednesdayDayNew==6){wednesdayDayNew="06"}
		if(wednesdayDayNew==7){wednesdayDayNew="07"}
		if(wednesdayDayNew==8){wednesdayDayNew="08"}
		if(wednesdayDayNew==9){wednesdayDayNew="09"}
		
		if(thursdayDayNew==1){thursdayDayNew="01"}
		if(thursdayDayNew==2){thursdayDayNew="02"}
		if(thursdayDayNew==3){thursdayDayNew="03"}
		if(thursdayDayNew==4){thursdayDayNew="04"}
		if(thursdayDayNew==5){thursdayDayNew="05"}
		if(thursdayDayNew==6){thursdayDayNew="06"}
		if(thursdayDayNew==7){thursdayDayNew="07"}
		if(thursdayDayNew==8){thursdayDayNew="08"}
		if(thursdayDayNew==9){thursdayDayNew="09"}
		
		if(fridayDayNew==1){fridayDayNew="01"}
		if(fridayDayNew==2){fridayDayNew="02"}
		if(fridayDayNew==3){fridayDayNew="03"}
		if(fridayDayNew==4){fridayDayNew="04"}
		if(fridayDayNew==5){fridayDayNew="05"}
		if(fridayDayNew==6){fridayDayNew="06"}
		if(fridayDayNew==7){fridayDayNew="07"}
		if(fridayDayNew==8){fridayDayNew="08"}
		if(fridayDayNew==9){fridayDayNew="09"}
		
		if(mondayMonthNew==1){mondayMonthNew="01"}
		if(mondayMonthNew==2){mondayMonthNew="02"}
		if(mondayMonthNew==3){mondayMonthNew="03"}
		if(mondayMonthNew==4){mondayMonthNew="04"}
		if(mondayMonthNew==5){mondayMonthNew="05"}
		if(mondayMonthNew==6){mondayMonthNew="06"}
		if(mondayMonthNew==7){mondayMonthNew="07"}
		if(mondayMonthNew==8){mondayMonthNew="08"}
		if(mondayMonthNew==9){mondayMonthNew="09"}
		
		if(tuesdayMonthNew==1){tuesdayMonthNew="01"}
		if(tuesdayMonthNew==2){tuesdayMonthNew="02"}
		if(tuesdayMonthNew==3){tuesdayMonthNew="03"}
		if(tuesdayMonthNew==4){tuesdayMonthNew="04"}
		if(tuesdayMonthNew==5){tuesdayMonthNew="05"}
		if(tuesdayMonthNew==6){tuesdayMonthNew="06"}
		if(tuesdayMonthNew==7){tuesdayMonthNew="07"}
		if(tuesdayMonthNew==8){tuesdayMonthNew="08"}
		if(tuesdayMonthNew==9){tuesdayMonthNew="09"}
		
		if(wednesdayMonthNew==1){wednesdayMonthNew="01"}
		if(wednesdayMonthNew==2){wednesdayMonthNew="02"}
		if(wednesdayMonthNew==3){wednesdayMonthNew="03"}
		if(wednesdayMonthNew==4){wednesdayMonthNew="04"}
		if(wednesdayMonthNew==5){wednesdayMonthNew="05"}
		if(wednesdayMonthNew==6){wednesdayMonthNew="06"}
		if(wednesdayMonthNew==7){wednesdayMonthNew="07"}
		if(wednesdayMonthNew==8){wednesdayMonthNew="08"}
		if(wednesdayMonthNew==9){wednesdayMonthNew="09"}
		
		if(thursdayMonthNew==1){thursdayMonthNew="01"}
		if(thursdayMonthNew==2){thursdayMonthNew="02"}
		if(thursdayMonthNew==3){thursdayMonthNew="03"}
		if(thursdayMonthNew==4){thursdayMonthNew="04"}
		if(thursdayMonthNew==5){thursdayMonthNew="05"}
		if(thursdayMonthNew==6){thursdayMonthNew="06"}
		if(thursdayMonthNew==7){thursdayMonthNew="07"}
		if(thursdayMonthNew==8){thursdayMonthNew="08"}
		if(thursdayMonthNew==9){thursdayMonthNew="09"}
		
		if(fridayMonthNew==1){fridayMonthNew="01"}
		if(fridayMonthNew==2){fridayMonthNew="02"}
		if(fridayMonthNew==3){fridayMonthNew="03"}
		if(fridayMonthNew==4){fridayMonthNew="04"}
		if(fridayMonthNew==5){fridayMonthNew="05"}
		if(fridayMonthNew==6){fridayMonthNew="06"}
		if(fridayMonthNew==7){fridayMonthNew="07"}
		if(fridayMonthNew==8){fridayMonthNew="08"}
		if(fridayMonthNew==9){fridayMonthNew="09"}
		
		$("#mondayDate").text(mondayDayNew+"/"+mondayMonthNew+"/"+mondayYearNew)
		$("#tuesdayDate").text(tuesdayDayNew+"/"+tuesdayMonthNew+"/"+tuesdayYearNew)
		$("#wednesdayDate").text(wednesdayDayNew+"/"+wednesdayMonthNew+"/"+wednesdayYearNew)
		$("#thursdayDate").text(thursdayDayNew+"/"+thursdayMonthNew+"/"+thursdayYearNew)
		$("#fridayDate").text(fridayDayNew+"/"+fridayMonthNew+"/"+fridayYearNew)	
		
		positionAllActivities(1);
		
		}//close Else loop that started all the way in the beginning of this function
	
	});
});

function calculateMarginsOnResize(){
	var bodyWidth = parseFloat($("body").css("width"));
	var middleSectionWidth = parseFloat($("#middleSection").css("width"));
	$("#middleSection").css("margin-left", ((bodyWidth-middleSectionWidth)/2)+ "px");
	var middleSectionMargin = ((bodyWidth-middleSectionWidth)/2);
	var usernamePadding = parseFloat($("#usernameTopDiv").css(
			"paddingLeft"));
	var usernameWidth = parseFloat($("#usernameTopDiv").css("width"));
	var navBarMargin = middleSectionMargin - usernamePadding
			- usernameWidth;
	$("#navigationBar").css("margin-left", navBarMargin + "px");
}